define(function(require,exports,module){
	var Grid = require("grid");
	var Dialog = require("dialog");
	
	module.exports = {
		initComponent: function(widget){
			var grid = new Grid({
				parentNode: ".J-grid",
				autoRender: false,
				model: {
					url: "api/groupreserve/querygroup",
					params: function(){
						var subnav = widget.get("subnav");
						var time = subnav.getValue("time");
						var alliance = subnav.getValue("alliance");
						var obj = {
							"planItemGroup.alliance": alliance,
							"groupReserve.checkInTypeIn": "Alliance,Organization",
							"planItemGroup.servicePoint": alliance == "false" ? 
									subnav.getValue("servicePoint") : null,
							"planItemGroup.planItem.destination": subnav.getValue("destination"),
							"planItemGroup.planItem.startDate": time.start,
							"planItemGroup.planItem.startDateEnd": time.end,
							"planItemGroup.checkInStatusIn": "Initial,Reserve,CheckIn",	
							fetchProperties: widget.store.getGridFetchProperties()
						}
						if(alliance == "false"){
							obj["planItemGroup.signUpStatusIn"] = "Review,AdjustmentReview";
						}
						
						return obj;
					},
					columns: [{
						name: "planItemGroup.planItem.startDate",
						label: "年度",
						format: "date",
						formatparams: {
							mode: "YYYY"
						}
					},{
						name: "planTitle",
						label: "计划名称"
					},{
						name: "verNumber",
						label: "版本号"
					},{
						name: "planItemGroup.planItem.destination.name",
						label: "目的地"
					},{
						name: "planItemGroup.planItem.startDate",
						label: "开始日期",
						format: "date"
					},{
						name: "planItemGroup.planItem.endDate",
						label: "结束日期",
						format: "date"
					},{
						name: "signUpNumber",
						label: "报名人数"
					},{
						name: "allOrSer",
						label: "组团单位",
						format: function(value, row){
							if(row.planItemGroup.allianceOrg == null){
								return row.planItemGroup.servicePoint.name;
							}else{
								return row.planItemGroup.allianceOrg.name;
							}
						}
					},{
						name: "planItemGroup.checkInStatus.value",
						label: "状态"
					},{
						name: "groupReserve.reserveDate",
						label: "预约日期",
						format: "date"
					},{
						name: "groupReserve.operator.name",
						label: "预约人"
					},{
						name: "operate",
						label: "操作",
						format: "button",
						formatparams: [{
							id: "appoint",
							text: "选房",
							handler: function(index,data,rowEL){
								widget.handler.grid.handleAppointClick(widget,data);
							},
							show: function(value,row){
								return row.planItemGroup.checkInStatus.key == "Initial"
							}
						},{
							id: "detail",
							text: "查看",
							handler: function(index,data,rowEL){
								widget.handler.grid.handleDetailClick(widget,data);
							},
							show: function(value,row){
								return row.planItemGroup.checkInStatus.key != "Initial"
							}
						}]
					}]
				}
			});
			widget.set("grid",grid);
		}
	};
});